<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;
use common\collection\Common;
use common\collection\BackendCommon;
use common\helpers\PublicFun;
use backend\config\routeParams;


/**
 * Site controller
 */
class SiteController extends Controller
{

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }

    public  function beforeAction($action){
       if(BackendCommon::init()){
           return true;
       }else{
           Yii::$app->response->redirect( ['login/index']);
       }

    }
    //首页
    public function actionIndex()
    {
        $JsonData['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('GetMytipInfo');
        $result1 = PublicFun::PostPackage($JsonData, $url);
        $result1 = json_decode($result1['Body'],true);
        $Info = $result1['Model'];
        $post = [];
        if($Info['AccountType'] == 100){
            $post['PageNo'] = 1;
            $post['PageSize'] = 10;
            $url = routeParams::HttpUrl('PCHomeDataForPlatformGet');
        }else{
            $post['LoginMytipId'] = Common::GetMytipId();
            $url = routeParams::HttpUrl('PCHomeDataGet');
        }
        $result = PublicFun::PostPackage($post, $url);
        $result = json_decode($result['Body'],true);
       return $this->render('index',array('ret'=>$result,'AccountType' =>$Info['AccountType'] ));
    }

    // 消息中心
    public function actionNewscenter()
    {
        return $this->render('newscenter');
    }

    public function actionInfo()
    {
       $datapost = Yii::$app->request->post();
       $datapost = Common::ArrayFilter($datapost);
       $cookies = Yii::$app->request->cookies;
       $admin = $cookies->get('MytipIdBack')->value;
       $datapost['LoginMytipId'] = $admin;
       $route = 'PCHomeDataGet';
       $url = routeParams::HttpUrl($route);
       $result = PublicFun::PostPackage($datapost, $url);
       $result = json_decode($result['Body'],true);
       die(json_encode($result));
    }
    public function actionGetNoticeType()
    {
       $post = Yii::$app->request->post();
       $post = Common::ArrayFilter($post);
       $post['MytipId'] = Common::GetMytipId();
       $url = routeParams::HttpUrl('FNoticeTypeGetList');
       $result = PublicFun::PostPackage($post, $url);
       $result = json_decode($result['Body'],true);
       die(json_encode($result));
    }

    //获取我的软文列表
    public function actionGetNoticeList()
    {
        $datapost = Yii::$app->request->post();
        $datapost = Common::ArrayFilter($datapost);
        $admin =  Common::GetMytipId();
        $datapost['MytipId'] = $admin;
        $url = routeParams::HttpUrl('PCNoticeGetList');
        $result = PublicFun::PostPackage($datapost, $url);
        $result = json_decode($result['Body'],true);
        $ret = [
            'PageNo' => $datapost['PageNo'],
            'PageSize' => $datapost["PageSize"],
            'total' => $result["TotalCount"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }
    public function actionNoticeDelete()
    {
        $post = Yii::$app->request->post();
        $post = Common::ArrayFilter($post);
        $post['UserId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('PCNoticeDelete');
        $result = PublicFun::PostPackage($post, $url);
        $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    //消息置为已读
    public function actionNoticeRead()
    {
        $post = Yii::$app->request->post();
        $post = Common::ArrayFilter($post);
        $post['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('PCNoticeDetail');
        $result = PublicFun::PostPackage($post, $url);
        $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //获取企业信息
    public function actionCompany()
    {
        return $this->render('company');
    }
    //保存企业信息
    public function actionEnterpriseInfoSave()
    {
        $post = Yii::$app->request->post();
        $post = Common::ArrayFilter($post);
        $post['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseInfoSaveByEnt');
        $result = PublicFun::PostPackage($post, $url);
        $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    //保存企业信息
    public function actionEnterpriseDetail()
    {
        $post = Yii::$app->request->post();
        $post = Common::ArrayFilter($post);
        $post['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseInfoGetDetial');
        $result = PublicFun::PostPackage($post, $url);
        $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //版本续费
    public function actionEnterpriseVersionRenew()
    {
        $post = Yii::$app->request->post();
        $post = Common::ArrayFilter($post);
        $post['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseVersionRenew');
        $result = PublicFun::PostPackage($post, $url);
        $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //版本续费
    public function actionGetHomeData(){
        $post = Yii::$app->request->post();
        $post = Common::ArrayFilter($post);
        $JsonData['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('GetMytipInfo');
        $result1 = PublicFun::PostPackage($JsonData, $url);
        $result1 = json_decode($result1['Body'],true);
        $Info = $result1['Model'];
        if($Info['AccountType'] == 100){
            $url = routeParams::HttpUrl('PCHomeDataForPlatformGet');
        }else{
            $post['LoginMytipId'] = Common::GetMytipId();
            $url = routeParams::HttpUrl('PCHomeDataGet');
        }
        $result = PublicFun::PostPackage($post, $url);
        $result = json_decode($result['Body'],true);
        $result['AccountType'] = $Info['AccountType'];
        die(json_encode($result));

    }



}
